package com.cloudconsumerfeignhystrix.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import com.cloudconsumerfeignhystrix.service.PaymentHystrixService;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;

@RestController
@Slf4j
@DefaultProperties(defaultFallback = "payment_Global_FallbackMethod")
public class OrderHystirxController {
	
	@Autowired
	private PaymentHystrixService paymentHystrixService;

	@GetMapping("/consumer/hystrix/ok/{id}")
	String paymentInfo_OK(@PathVariable("id") Integer id) {
		log.info("OrderHystirxController--paymentInfo_OK的id是：" + id);
		return paymentHystrixService.paymentInfo_OK(id);
	}

	/**
	 * 默认的fallback注解
	 * @param id
	 * @return
	 */
    @HystrixCommand
	@GetMapping("/consumer/payment/hystrix/timeout/{id}")
	public String paymentInfo_TimeOut(@PathVariable("id") Integer id) {

		return paymentHystrixService.paymentInfo_TimeOut(id);
	}
    
    /**
     * 全局fallback
     * @return
     */
    public String payment_Global_FallbackMethod() {
        return "Global异常处理信息,请稍后重试.o(╥﹏╥)o";
    }

	
}
